package me.jiatao.baselibrary.common


/**
 *  基础常量
 */
class BaseConstant private constructor() {
    companion object {
        /**
         * 网络监控常量
         */
        const val ACTION_CONNECTIVITY_CHANGE = "android.net.conn.CONNECTIVITY_CHANGE"

        /**
         * 网络相关
         */
        //本地服务器地址
        const val HTTP_SERVER_ADDRESS = "https://www.wanandroid.com/"
        const val HTTP_DEFAULT_TIMEOUT: Long = 15
        const val HTTP_SET_COOKIE_KEY = "set-cookie"
        const val HTTP_COOKIE_NAME = "Cookie"
        const val HTTP_MAX_CACHE_SIZE: Long = 1024 * 1024 * 50 // 50M 的缓存大小


        /**
         * sp相关参数
         */
        //SP表名
        const val SP_FILE_NAME = "wan_android"
        //Token Key
        const val SP_KEY_TOKEN = "token"

        const val SP_HAS_NETWORK_KEY = "has_network_key"


        /**
         * 业务相关
         */
        const val SAVE_USER_LOGIN_KEY = "user/login"
        const val SAVE_USER_REGISTER_KEY = "user/register"
        fun urlSaveCookie(url: String): Boolean {
            return arrayOf(
                SAVE_USER_LOGIN_KEY,
                SAVE_USER_REGISTER_KEY
            ).any { host ->
                url.contains(host)
            }
        }

        const val COLLECTIONS_WEBSITE = "lg/collect"
        const val UNCOLLECTIONS_WEBSITE = "lg/uncollect"
        const val ARTICLE_WEBSITE = "article"
        const val TODO_WEBSITE = "lg/todo"
        const val COIN_WEBSITE = "lg/coin"

        fun urlWithToken(url: String): Boolean {
            return arrayOf(
                COLLECTIONS_WEBSITE,
                UNCOLLECTIONS_WEBSITE,
                ARTICLE_WEBSITE,
                TODO_WEBSITE,
                COIN_WEBSITE
            ).any { host ->
                url.contains(host)
            }
        }
    }
}
